#ifndef N1NOTIFICATIONCENTER_H_2006_06_26
#define N1NOTIFICATIONCENTER_H_2006_06_26

#include "N1Object.h"
#include "N1String.h"
#include "N1Delegate.h"
#include "N1Dictionary.h"

class N1NotificationCenter : public N1Object {
public:
    N1NotificationCenter();
    virtual ~N1NotificationCenter();

    N1NAME_DECL

    typedef N1DelegatePtr<void, N1Dictionary*>  N1NotificationDelegate;

    template<class Handler>
    void addObserver(N1AnsiString *notification, Handler &obj, void (Handler::*Func)(N1Dictionary*))
    {
        N1NotificationRecord *record = (N1NotificationRecord*)m_dict->objectForKey(notification);
        if(record==NULL) 
        {
            N1NotificationDelegate *observer = new N1NotificationDelegate(&obj, Func);
            m_dict->setObject(notification, observer);
        }
    };

protected:
    class N1NotificationRecord : public N1Object {
    public:
        N1NotificationRecord(N1NotificationDelegate* ptr) { m_observer = ptr; };
        virtual ~N1NotificationRecord() { delete m_observer; };
        virtual pcstr name() const { return "N1NotificationRecord"; };
        N1NotificationDelegate* getDelegate() { return m_observer; };
    private:
        N1NotificationDelegate* m_observer;
    };

    N1Dictionary *m_dict;
};

#endif //N1NOTIFICATIONCENTER_H_2006_06_26
